<%--
  Created by IntelliJ IDEA.
  User: Boss
  Date: 2021/5/10
  Time: 8:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户还书</title>
</head>
<link rel="stylesheet" type="text/css" href="layui/css/layui.css">
<body>
<%
    String path=request.getContextPath();
    String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<div>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
        <legend>用户还书</legend>
    </fieldset>
    <form action="<%=basePath%>BorrowServlet?opr=insertSelect" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">读者卡号</label>
            <div class="layui-input-block">
                <input type="text" name="cardId" required  lay-verify="required" placeholder="请输入读者卡号" autocomplete="off" class="layui-input hCardId">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">书籍编号</label>
            <div class="layui-input-block">
                <input type="text" name="bookId" required  lay-verify="required" placeholder="请输入书籍编号" autocomplete="off" class="layui-input hBookId">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">归还时间</label>
            <div class="layui-input-block">
                <input type="text" name="endTime" required  lay-verify="required" placeholder="请输入归还时间" autocomplete="off" class="layui-input hEndTime">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="button" name="HTrue" class="layui-btn" lay-submit lay-filter="formDemo" value="确认还书">
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script src="js/jquery-1.12.4.js"></script>
<script src="layui/layui.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("input[name='HTrue']").click(function () {
            let cardId = $(".hCardId").val();
            let BookId = $(".hBookId").val();
            let EndTime = $(".hEndTime").val();
            $.ajax({
                url: "BorrowServlet?opr=insertSelect",
                type: "post",
                data: {
                    cardId: cardId,
                    bookId: BookId,
                    endTime: EndTime
                },
                dataType: "json",
                success: function (date) {
                    if (date) {
                        layer.open({
                            content: '还书成功！',
                            success: function (layero, index) {
                                console.log(layero, index);
                            }
                        });
                    }else {
                        layer.open({
                            content: '还书失败！',
                            success: function (layero, index) {
                                console.log(layero, index);
                            }
                        });
                    }
                }
            })
        });
    })
</script>
</body>
</html>
